﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="medium" label-width="100px" label-position="right" :disabled="setting.readonly">
				<el-col :span="12" v-if="JudgeShow('Reimbursement')">
					<el-form-item label="报销单号" prop="reimbursement">
						<el-input v-model="dataForm.reimbursement" placeholder="系统自动生成" readonly :disabled="JudgeWrite('Reimbursement')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('Handler')">
					<el-form-item label="报销人" prop="handler">
						<el-input v-model="dataForm.handler" placeholder="系统自动生成" readonly :disabled="JudgeWrite('Handler')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('ProId')">
					<el-form-item label="所属项目" prop="proId">
						<el-select v-model="dataForm.proId" placeholder="请选择" clearable required :disabled="JudgeWrite('ProId')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in proIdOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('HappedTime')">
					<el-form-item label="发生时间" prop="happedTime">
						<el-date-picker v-model="dataForm.happedTime" placeholder="请选择" clearable required :disabled="JudgeWrite('HappedTime')" :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('CategoryId')">
					<el-form-item label="报销类别" prop="categoryId">
						<el-select v-model="dataForm.categoryId" placeholder="请选择" clearable required :disabled="JudgeWrite('CategoryId')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in categoryIdOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('Total_Amount')">
					<el-form-item label="报销总额" prop="totalAmount">
						<el-input-number v-model="dataForm.totalAmount" placeholder="数字文本" required :disabled="JudgeWrite('Total_Amount')" :step="100" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('Remark')">
					<el-form-item label="报销事由" prop="remark">
						<el-input v-model="dataForm.remark" placeholder="请输入" clearable required :disabled="JudgeWrite('Remark')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('Appendix')">
					<el-form-item label="附件" prop="appendix">
						<JNPF-UploadFz v-model="dataForm.appendix" :disabled="JudgeWrite('Appendix')" :fileSize="20" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
                <el-col :span="24" v-if="JudgeShow('tableField109')">
                    <el-form-item label-width="0">
                        <el-table :data="dataForm.zyOaWfFinrmbtDetailsList" size='mini'>
                            <el-table-column type="index" width="50" label="序号" align="center" />
                            <el-table-column prop="costType" label="费用类别">
                                <template slot-scope="scope">
                                    <el-select v-model="scope.row.costType" placeholder="请选择" clearable :disabled="JudgeWrite('tableField109')" >
										<el-option v-for="(item, index) in costTypeOptions" :key="index" :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
									</el-select>
                                </template>
                            </el-table-column>
                            <el-table-column prop="costItem" label="费用项目">
                                <template slot-scope="scope">
									<el-input v-model="scope.row.costItem"  placeholder="请输入" clearable ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column prop="costAmount" label="报销金额">
                                <template slot-scope="scope">
									<el-input-number v-model="scope.row.costAmount"  placeholder="数字文本" ></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column prop="remarks" label="备注说明">
                                <template slot-scope="scope">
									<el-input v-model="scope.row.remarks"  placeholder="请输入" clearable ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" width="50">
								<template slot-scope="scope">
									<el-button size="mini" type="text" class="JNPF-table-delBtn" @click="handleDelZyOaWfFinrmbtDetailsEntityList(scope.$index)">删除</el-button>
								</template>
							</el-table-column>
						</el-table>
						<div class="table-actions" @click="addHandleZyOaWfFinrmbtDetailsEntityList()">
							<el-button type="text" icon="el-icon-plus">新增</el-button>
						</div>
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="false" >
					<el-form-item label="创建时间" prop="createTime">
						<el-input v-model="dataForm.createTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('CreateTime')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="false" >
					<el-form-item label="修改人" prop="modifyPerson">
						<el-input v-model="dataForm.modifyPerson" placeholder="系统自动生成" readonly :disabled="JudgeWrite('ModifyPerson')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="false" >
					<el-form-item label="修改时间" prop="modifyTime">
						<el-input v-model="dataForm.modifyTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('ModifyTime')" >
						</el-input>
					</el-form-item>
				</el-col>
            </el-form>
        </el-row>
        <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit" />
    </div>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		data(){
			return {
				visible: false,
				setting:{},
				eventType: '',
				userBoxVisible:false,
				dataForm: {
					id:'',
					reimbursement:undefined,
					handler:undefined,
					proId:undefined,
					happedTime:undefined,
					categoryId:undefined,
					totalAmount:0,
					remark:undefined,
					appendix:[],
					zyOaWfFinrmbtDetailsList:[],
					createTime:undefined,
					modifyPerson:undefined,
					modifyTime:undefined,
				},
				rules: {
					proId:[
						{
							required:true,
							message:'请输入所属项目',
							trigger:'change'
						},
					],
					happedTime:[
						{
							required:true,
							message:'请输入发生时间',
							trigger:'change'
						},
					],
					categoryId:[
						{
							required:true,
							message:'请输入报销类别',
							trigger:'change'
						},
					],
					totalAmount:[
						{
							required:true,
							message:'请输入报销总额',
							trigger:["blur","change"]
						},
					],
					remark:[
						{
							required:true,
							message:'请输入报销事由',
							trigger:'blur'
						},
					],
				},
				proIdOptions : [],
				categoryIdOptions : [],
				costTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getproIdOptions();
			this.getcategoryIdOptions();
			this.getcostTypeOptions();
		},
		mounted() {},
		methods: {
			getproIdOptions(){
				previewDataInterface('195045591036724485').then(res => {
					this.proIdOptions = res.data
				});
			},
			getcategoryIdOptions(){
				getDictionaryDataSelector('193257630150427909').then(res => {
					this.categoryIdOptions = res.data.list
				});
			},
			getcostTypeOptions(){
				getDictionaryDataSelector('3e2d33e54d554b4b8a33fc41b93f8a2d').then(res => {
					this.costTypeOptions = res.data.list
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(data) {
				this.dataForm.id = data.id || 0;
                this.loading = true
				this.setting = data
				this.visible = true;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyOaWfFinrmbt/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
					else{
						this.dataForm.flowId = data.flowId
					}
					this.loading = false
					this.$emit('setPageLoad')
				})
			},
			dataFormSubmit(eventType) {				
				this.$refs['elForm'].validate((valid) => {
					if (valid) {
						if (eventType === 'audit' || eventType === 'reject') {
            				this.$emit('eventReciver', this.dataForm, eventType)
            				return
          				}
						this.dataForm.flowState = eventType === 'submit' ? 0 : 1
						this.eventType = eventType
						if (this.eventType === 'submit') {
							this.$confirm('您确定要提交当前流程吗, 是否继续?', '提示', {
								type: 'warning'
							}).then(() => {
								this.request()
							}).catch(() => { });
						} else {
							this.request()
						}
					}
				})
			},
			request() {
				if (!this.dataForm.id) {
					delete (this.dataForm.id)
					request({
						url: '/api/SubDev/ZyOaWfFinrmbt',
						method: 'post',
						data: this.dataForm
					}).then((res) => {
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false
								this.$emit('close', true)
							}
						})
					})
				}else{
					request({
						url: '/api/SubDev/ZyOaWfFinrmbt/' + this.dataForm.id,
						method: 'PUT',
						data: this.dataForm
					}).then((res) => {
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false
								this.$emit('close', true)
							}
						})
					})
				}
			},
			JudgeShow(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length) return true
				let arr = this.setting.formOperates.filter(o => o.id === id) || []
				if (!arr.length) return true
				let item = arr[0]
				return item.read
			},
			JudgeWrite(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length) return false
				let arr = this.setting.formOperates.filter(o => o.id === id) || []
				if (!arr.length) return true
				let item = arr[0]
				return !item.write
			},
			addHandleZyOaWfFinrmbtDetailsEntityList() {
				let item = {
					costType:undefined,
					costItem:undefined,
					costAmount:0,
					remarks:undefined,
				}
				this.dataForm.zyOaWfFinrmbtDetailsList.push(item)
			},
			handleDelZyOaWfFinrmbtDetailsEntityList(index) {
				this.dataForm.zyOaWfinrmbtDetailsList.splice(index, 1);
			},
		}
	}
</script>

